package com.cafe.service.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cafe.dao.ProductCategoryDao;
import com.cafe.model.ProductCategory;
import com.cafe.service.ProductCategoryService;
import com.malamute.core.common.Page;

/**
 * @description 产品目录业务接口实现
 * @version v1.0
 */
@Service
public class ProductCategoryServiceImpl implements ProductCategoryService {
	@Autowired
	private ProductCategoryDao productCategoryDao;

	/*
	 * (non-Javadoc)
	 * 
	 * @param menuCategory
	 * 
	 * @see
	 * com.cafe.service.MenuCategoryService#saveMenuCategory(com.cafe.model.
	 * MenuCategory)
	 */
	@Override
	public void saveProductCategory(ProductCategory productCategory) {
		productCategoryDao.save(productCategory);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @param menuCategory
	 * 
	 * @see
	 * com.cafe.service.MenuCategoryService#updateMenuCategory(com.cafe.model
	 * .MenuCategory)
	 */
	@Override
	public void updateProductCategory(ProductCategory productCategory) {
		productCategoryDao.update(productCategory);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @param id
	 * 
	 * @see
	 * com.cafe.service.MenuCategoryService#deleteMenuCategoryById(java.lang
	 * .Integer)
	 */
	@Override
	public void deleteProductCategoryById(Integer id) {
		productCategoryDao.deleteByKey(id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @param id
	 * 
	 * @return
	 * 
	 * @see
	 * com.cafe.service.MenuCategoryService#getMenuCategoryById(java.lang.Integer
	 * )
	 */
	@Override
	public ProductCategory getProductCategoryById(Integer id) {
		return productCategoryDao.get(id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @param criteria
	 * 
	 * @param page
	 * 
	 * @see
	 * com.cafe.service.MenuCategoryService#listMenuCategoriesByPage(org.hibernate
	 * .criterion.DetachedCriteria, com.malamute.core.common.Page)
	 */
	@Override
	public void listProductCategoriesByPage(DetachedCriteria criteria, Page page) {
		productCategoryDao.listByPage(criteria, page);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @param criteria
	 * 
	 * @return
	 * 
	 * @see
	 * com.cafe.service.MenuCategoryService#listAllMenuCategory(org.hibernate
	 * .criterion.DetachedCriteria)
	 */
	@Override
	public List listAllProductCategory(DetachedCriteria criteria) {
		return productCategoryDao.findByCriteria(criteria);
	}

	@Override
	public void exchangeOrder(ProductCategory source, ProductCategory target) {
		int tmp = source.getOrderNum();
		source.setOrderNum(target.getOrderNum());
		target.setOrderNum(tmp);
		productCategoryDao.save(source);
		productCategoryDao.save(target);

	}


}
